import type { OrderCreateDto, OrderUpdateDto, OrderListDto, OrderSingleDto } from "@/dtos/order.dto";
import type { PageRequest } from "@/types";
import http from "@/utils/http";

/**
 * 获取订单列表
 * @param params - 分页参数
 * @returns 包含订单列表、总数和总页数的对象
 */
export function getOrderListApi(params: PageRequest) {
  return http.get<any, { list: OrderListDto[]; total: number; pages: number }>("/orders", { params });
}

/**
 * 获取单个订单
 * @param orderId - 订单ID
 * @returns 订单的详细信息
 */
export function getOrderApi(orderId: string) {
  return http.get<any, OrderSingleDto>(`/orders/${orderId}`);
}

/**
 * 创建订单
 * @param data - 订单创建数据
 * @returns 创建成功的布尔值
 */
export function createOrderApi(data: OrderCreateDto) {
  return http.post<any, boolean>("/orders", data);
}

/**
 * 更新订单
 * @param orderId - 订单ID
 * @param data - 订单更新数据
 * @returns 更新成功的布尔值
 */
export function updateOrderApi(orderId: string, data: OrderUpdateDto) {
  return http.put<any, boolean>(`/orders/${orderId}`, data);
}

/**
 * 删除订单
 * @param orderId - 订单ID
 * @returns 删除成功的布尔值
 */
export function deleteOrderApi(orderId: string) {
  return http.delete<any, boolean>(`/orders/${orderId}`);
}